package com.tanhua.common.service;

import com.tanhua.common.enums.TypeEnum;
import com.tanhua.common.mapper.JournalMapper;
import com.tanhua.common.mapper.UserInfoMapper;
import com.tanhua.common.pojo.Journal;
import com.tanhua.common.pojo.User;
import com.tanhua.common.pojo.UserInfo;
import com.tanhua.common.utils.UserThreadLocal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class JournalApiService{
    @Autowired
    private JournalMapper journalMapper;

    @Autowired
    private UserInfoMapper userInfoMapper;

    public Boolean saveLog(String type, String describes) {
        try {
            User user = UserThreadLocal.get();
            UserInfo userInfo = userInfoMapper.selectById(20);

            Journal journal = new Journal();
            journal.setName(userInfo.getNickName());
//            TypeEnum[] values = TypeEnum.values();
//            for (TypeEnum value : values) {
//                if (value.getValue().equals(type)){
//                    journal.setType(value.getValue());
//                }
//            }
            journal.setType(type);
            journal.setDescribes(describes);
            journal.setRouter("192.168.31.81");
            journal.setCreated(new Date());

            int insert = journalMapper.insert(journal);
            if (insert>0){
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
